import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex)

interface AppState {
  collapse: boolean
  user: any
  menuList: any[]
  resourceList: any[]
}

export default new Vuex.Store({
  state: {
    collapse: false,
    user: JSON.parse(window.localStorage.getItem('user') || 'null'),
    menuList: [],
    resourceList: []
  },
  mutations: {
    setUser (state: AppState, payload: string) {
      state.user = JSON.parse(payload)
      window.localStorage.setItem('user', payload)
    },
    updateCollapse (state: AppState, payload: boolean) {
      state.collapse = payload
    },
    updatePermission (state: AppState, payload: {
      menuList: any[]
      resourceList: any[]
    }) {
      state.menuList = payload.menuList
      state.resourceList = payload.resourceList
    }
  },
  actions: {
  },
  modules: {
  }
})
